home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / menuba.zip / TEST.ZIP / TEST.C < prev    next >
C/C++ Source or Header  |  1992-01-25  |  4KB  |  123 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: Test.c
  4.  
  5. ****************************************************************************/
  6.  
  7. #include "windows.h"
  8. #include "menudefs.h"
  9. #include "stdlib.h"
  10. WORD hDlgItem;
  11. static int nItems,ItemCount,SelectItem;
  12. char temp [10];
  13. BOOL FAR PASCAL TestProc(HWND, unsigned, WORD, LONG);
  14.  
  15. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  16. HANDLE hInstance;
  17. HANDLE hPrevInstance;
  18. LPSTR lpCmdLine;
  19. int nCmdShow;
  20. {  FARPROC lpTestProc;
  21.    lpTestProc = MakeProcInstance(TestProc, hInstance);
  22.    DialogBox(hInstance, "TESTBOX", NULL, lpTestProc);
  23.    FreeProcInstance(lpTestProc);
  24.    return (TRUE);
  25. }
  26.  
  27. /****************************************************************************/
  28.  
  29. BOOL FAR PASCAL TestProc(hDlg, message, wParam, lParam)
  30. HWND hDlg;
  31. unsigned message;
  32. WORD wParam;
  33. LONG lParam;
  34. { char str[17];
  35.   HWND hCtl;
  36.   int i;
  37.   switch (message)
  38.    {
  39.    case WM_INITDIALOG:
  40.          nItems=0;
  41.          ItemCount=0;
  42.          hCtl = GetDlgItem( hDlg, 100 );  /* combobox id */
  43.          SetFocus(hCtl);
  44.          SelectItem=-1;
  45.          return (TRUE);
  46.    break;
  47.  
  48.    case WM_COMMAND:
  49.        switch(wParam)
  50.             {
  51.             case 1:  /* ok */
  52.                EndDialog(hDlg, TRUE);
  53.                return (TRUE);
  54.             break;
  55.             case 100: /* select item */
  56.                hCtl = GetDlgItem( hDlg, 100 );  /* combobox id */
  57.                SelectItem=(int)SendMessage( hCtl, CB_GETCURSEL, 0, (LONG)(LPSTR)0 );
  58.             break;
  59.             case 101: /* add item */
  60.                ++nItems;
  61.                ++ItemCount;
  62.                SelectItem=ItemCount-1;
  63.                itoa(nItems,str,10);
  64.                lstrcpy((LPSTR)temp,(LPSTR)"Item");
  65.                lstrcat((LPSTR)temp,(LPSTR)str);
  66.                hCtl = GetDlgItem( hDlg, 100 );  /* combobox id */
  67.                SendMessage( hCtl, CB_ADDSTRING, 0, (LONG)(LPSTR)temp);
  68.                SendMessage( hCtl, CB_SETCURSEL, (WORD) ItemCount-1, (LONG)(LPSTR) 0 );
  69.                hCtl = GetDlgItem( hDlg, 110 );  /* static text id */
  70.                lstrcat((LPSTR)temp,(LPSTR)" added");
  71.                SetWindowText(hCtl,temp);
  72.             break;
  73.             case 102: /* modify item */
  74.                /* Get index of list box control selection. */
  75.                hCtl = GetDlgItem( hDlg, 100 );  /* combobox id */
  76.                if(SelectItem>=0)
  77.                  { /* modify */
  78.                    SendMessage( hCtl, CB_DELETESTRING, SelectItem, (LONG)(LPSTR)NULL);
  79.                    ++nItems;
  80.                    itoa(nItems,str,10);
  81.                    lstrcpy((LPSTR)temp,(LPSTR)"Item");
  82.                    lstrcat((LPSTR)temp,(LPSTR)str);
  83.                    SendMessage( hCtl, CB_INSERTSTRING, SelectItem, (LONG)(LPSTR)temp);
  84.                    SendMessage( hCtl, CB_SETCURSEL, (WORD) SelectItem, (LONG)(LPSTR) 0 );
  85.                    hCtl = GetDlgItem( hDlg, 110 );  /* static text id */
  86.                    lstrcat((LPSTR)temp,(LPSTR)" Added");
  87.                    SetWindowText(hCtl,temp);
  88.                  }
  89.             break;
  90.             case 103: /* delete item */
  91.                /* Get index of list box control selection. */
  92.                hCtl = GetDlgItem( hDlg, 100 );  /* combobox id */
  93.                if(SelectItem>=0)
  94.                  { /* delete */
  95.                    SendMessage( hCtl, CB_DELETESTRING, SelectItem, (LONG)(LPSTR)NULL);
  96.                    --ItemCount;
  97.                    SendMessage( hCtl, CB_SETCURSEL, (WORD) 0, (LONG)(LPSTR) 0 );
  98.                    hCtl = GetDlgItem( hDlg, 110 );  /* static text id */
  99.                    SetWindowText(hCtl,"Item Deleted");
  100.                  }
  101.              break;
  102.  
  103.             case 104: /* display item */
  104.                /* Get index of list box control selection. */
  105.                hCtl = GetDlgItem( hDlg, 100 );  /* combobox id */
  106.                i=(int)SendMessage( hCtl, CB_GETCURSEL, 0, (LONG)(LPSTR)0 );
  107.                lstrcpy((LPSTR)temp,(LPSTR)"");
  108.                SendMessage( hCtl, CB_GETLBTEXT,i, (LONG)(LPSTR)temp);
  109.                MessageBox(hDlg,(LPSTR)temp,"Selection",MB_OK);
  110.             break;
  111.  
  112.             case 105: /* display count */
  113.                itoa(ItemCount,temp,10);
  114.                MessageBox(hDlg,(LPSTR)temp,"Count",MB_OK);
  115.             break;
  116.         }
  117.        return (TRUE);
  118.  
  119.     }
  120.     return (FALSE);
  121.  
  122. }
  123.